<template>
	<view class="container">
		<!-- <view class="visitor">
		<view class="info">
			<view>姓名：{{infoData.name}}</view>
			<view style="color:rgba(0,0,0,0.45)">卡号：{{infoData.idNum}}</view>
		</view>
		<view class="btn" @click="showVisitCard=true">
			切换就诊人
		</view>
	</view> -->
		<view class="visitor">
			<view class="outside">
				<view class="within">
					<view class="info">
						<view class="name">
							<text>{{infoData.name}}</text>
							<!-- <text class="classType">【门诊】</text> -->
							<view class="btn m-l-30" @click="showVisitCard=true">
								<img src="@/static/images/qiehuan.png" style="width:29rpx;margin-right:8rpx;"></img>
								切换就诊人
							</view>
						</view>
						<view class="cord">
							卡号
						</view>
						<view>{{$desensitizationNormalStr(infoData.cardNum)}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="screenType">
			<view class="typeLeft">
				<uni-datetime-picker type="date" :end="endTime" v-model="beginTime"
					@change="beginChange($event)">{{beginTime}}</uni-datetime-picker>
				<view style="margin: 0 10rpx;">-</view>
				<uni-datetime-picker type="date" :start="beginTime" v-model="endTime"
					@change="endChange($event)">{{endTime}}</uni-datetime-picker>
			</view>
		</view>
		<view class="noCard" v-if="payList.length == 0">
			<view class="images">
				<img src="@/static/images/noCard.png" alt="">
				<view>
					未查询到信息
				</view>
			</view>
		</view>
		<view class="list" v-else>
			<scroll-view class="scroll-view_H" scroll-y="true" style="height: calc(100vh - 320rpx);">
				<view class="items" v-for="(item,index) in payList" :key="index">
					<view class="title_top">
						<text class="names">{{item.feeName +' / '+(item.unit || '')}}</text>
						<view class="btn">
							<text>支付成功</text>
						</view>
					</view>
					<view>
						<view class="icd">
							<text class="left">开单时间</text>
							<text>{{item.createTime != null && item.createTime != ''? item.createTime.substring(0,19):''}}</text>
						</view>
						<view class="icd">
							<text class="left">开单科室</text>
							<text>{{item.departName}}</text>
						</view>
						<view class="icd">
							<text class="left">执行科室</text>
							<text>{{item.executeDept}}</text>
						</view>
						<view class="time">
							<text class="left">实付款</text>
							<text class="moneyw"><text class="money">￥</text><text
									class="nums">{{item.amount}}</text></text>
						</view>
					</view>
					<view class="function_but">
						<view class="detail" @click="goDtl(item)">详情  <text class="more">>></text></view>
						<view v-if="isqydzfp == 1" class="item_but" @click="goElectronicInvoice(item)">电子发票</view>
					</view>

				</view>

			</scroll-view>

		</view>

		<!-- <liuCalendarDate ref="calendar2" isRange @checked='changeTime'></liuCalendarDate> -->
		<!-- 切换就诊人 -->
		<u-popup :show="showVisitCard" :round="10" :safeAreaInsetBottom="true" mode="bottom">
			<switchVisitCard :visitData="visitList" :relations="relationTrans" @closeVisit="close" />
		</u-popup>
	</view>
</template>

<script>
	import {
		getPatientBaseList
	} from "@/api/card/index.js"
	import {
		getConfigKey
	} from "@/api/home/home.js"
	
	import {
		getOutpatientPayMentList
	} from "@/api/pay/index.js"
	import switchVisitCard from '@/components/switchVisitCard/index.vue';
	import liuCalendarDate from '@/components/liu-calendar-date/liu-calendar-date.vue';
	import {
		getDictType
	} from "@/api/system/public.js";
	import {
		EventBus
	} from "@/utils/event-bus.js";
	export default {
		components: {
			switchVisitCard,
			liuCalendarDate
		},
		data() {
			return {
				isqydzfp:'',//是否启用电子发票  1启用 其他不启用
				infoData: {},
				timesRange: '',
				showTime: false,
				visitList: [],
				showVisitCard: false,
				relationTrans: {},
				beginTime: '',
				endTime: '',
				payList: [{
					departName: '信息科'
				}],
				checkedAll: ['all'],
				allAmount: '0.00',
				openid: '',
			}
		},
		onLoad(options) {
			let openid = uni.getStorageSync('openid') || ''
			this.openid = openid
			if (uni.getStorageSync('currentVisitCard')) {
				this.infoData = JSON.parse(uni.getStorageSync('currentVisitCard'))
			}
			let oneDay = 24 * 60 * 60 * 1000
			this.beginTime = this.$parseTime(new Date(Date.now() - 7 * oneDay), '{y}-{m}-{d}')
			this.endTime = this.$parseTime(new Date(), '{y}-{m}-{d}')
			this.getCardList()
			this.getDict()
			this.getList()
			this.getConfig();
		},
		onPullDownRefresh() {
			this.getList()
		},
		methods: {
			getCardList() {
				let params = {
					hospitalCode: JSON.parse(uni.getStorageSync('hospital')).hospitalCode,
					openId: this.openid,
				}
				getPatientBaseList(params).then(res => {
					if (res.code == 200) {
						this.visitList = res.rows
					}
				})
			},
			getList() {
				let obj = {
					name: this.infoData.name,
					cardNum: this.infoData.cardNum,
					beginTime: this.beginTime,
					endTime: this.endTime,
				}
				getOutpatientPayMentList(obj).then(res => {
					//数据请求完成之后停止下拉刷新
					uni.stopPullDownRefresh();
					this.payList = res.data || []

				})
			},
			goDtl(item) {
				uni.navigateTo({
					url: '/pages/mine/paymentRecords/details?info=' + JSON.stringify(item)
				})
			},
			/* 查看电子发票 */
			goElectronicInvoice(res) {
				console.log(res)
				uni.navigateTo({
					url: '/pages/mine/paymentRecords/electronicInvoice?inpNo=' + res.mzh + '&orderNo=' + res.lsh
				})
			},
			close() {
				this.showVisitCard = false
				EventBus.$emit('loadVisitor', '')
				if (uni.getStorageSync('currentVisitCard')) {
					this.infoData = JSON.parse(uni.getStorageSync('currentVisitCard'))
				}
				this.getList()
			},
			/* 开始日期 */
			beginChange(e) {
				this.getList()
			},
			/* 结束日期 */
			endChange(e) {
				this.getList()
			},
			/* 字典 */
			getDict() {
				getDictType({
					dictType: 'sys_relation'
				}).then(res => {
					if (res.code == 200) {
						res.rows.forEach(item => {
							this.relationTrans[item.dictValue] = item.dictLabel
						})
					}
				})
			},
			/* 获取参数配置 */
			getConfig() {
				getConfigKey('isqydzfp').then(res => {
					this.isqydzfp = res.msg
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: rgb(245, 245, 245);
	}

	.footer_btn {
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: space-around;
		text-align: center;
		width: 100%;
		padding: 24rpx;
		background-color: #fff;

		.u-button {
			width: 40%;
		}
	}

	.noCard {
		width: 100%;
		text-align: center;
		color: #666666;
		padding: 24rpx 0 0 0;
		margin-top: 72rpx;
		color: #808080;

		.images {
			width: 100%;
			margin-bottom: 40rpx;
			color: #666666;

			img {
				width: 55%;
				text-align: center;
			}
		}
	}

	.list {
		padding-top: 24rpx;

		.items {
			background-color: #fff;
			border-radius: 8px;
			padding-bottom: 18rpx;
			margin: 0 24rpx 24rpx 24rpx;

			.function_but {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 12px;
				.item_but {
					font-size: 12px;
					color: #ffffff;
					font-weight: bold;
					padding: 5px 15px;
					background-color: #5c93f9;
					border-radius: 4px;
				}
				.detail{
					font-size: 12px;
					color: #5c93f9;
					.more{
						padding-left: 4px;
						vertical-align: middle;
						font-size: 18px;
					}
				}
			}


			.title_top {
				padding: 24rpx;
				display: flex;
				font-size: 28rpx;
				font-weight: 600;
				align-items: center;
				border-bottom: 1rpx solid #eee;
				margin-bottom: 12rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.ischeck_ico {
					display: flex;
					align-items: center;
				}

				.names {
					flex: 1;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					margin-left: 12rpx;
				}

				.btn {
					font-size: 28rpx;
					color: #36D092;
				}
			}

			.name,
			.icd,
			.time,
			.dept {
				display: flex;
				justify-content: space-between;
				padding: 12rpx 24rpx;
				font-size: 28rpx;

				.left {
					color: #999;
					width: 130rpx;
				}

				.payBtn {
					border-radius: 20px;
					background-color: #4D8EFF;
					color: #fff;
					padding: 8rpx 24rpx;
					text-align: center;
				}

				.moneyw {
					display: flex;
					font-size: 24rpx;
					color: #999;

					.money {
						color: #000;
					}

					.nums {
						font-size: 40rpx;
						color: #000;
					}
				}
			}
		}


	}

	.screenType {
		width: 100%;
		display: flex;
		align-items: center;
		padding: 20rpx;
		background-color: rgb(92, 147, 249);
		justify-content: space-around;
		color: #fff;

		.typeLeft,
		.typeRight {
			display: flex;
			flex: 1;
			text-align: center;
			align-items: center;
		}
	}

	.visitor {
		width: 100%;
		// background-color: rgb(92, 147, 249);
		background: url('@/static/images/report-small-bg.png') no-repeat left center, linear-gradient(180deg, rgba(197, 218, 255, 1) 0%, rgba(92, 147, 249, 1) 100%);
		background-size: auto 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx 24rpx 0 24rpx;
		color: #3C537D;

		.outside {
			width: 100%;
			background-color: #fff;
			padding: 12rpx 12rpx 0 12rpx;
			border-radius: 8px 8px 0 0;
			background: url('@/static/images/card_bg.png') no-repeat;
			background-size: 100% 100%;

			.within {
				border-radius: 8px 8px 0 0;

				.info {
					padding: 16rpx 28rpx 20rpx;
					font-size: 34rpx;

					.name {
						display: flex;
						align-items: center;

						.classType {
							display: inline-block;
							margin: 0 36rpx;
						}

						.btn {
							font-size: 28rpx;
							padding: 7rpx 14rpx;
							background: linear-gradient(90deg, rgba(77, 142, 255, 1) 0%, rgba(94, 150, 247, 1) 100%);
							color: #fff;
							display: flex;
							align-items: center;
							border-radius: 5px;
						}
					}

					.cord {
						font-size: 28rpx;
						padding: 16rpx 0 8rpx;
					}
				}
			}
		}
	}
</style>